<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>骡窝窝系统管理平台</title>
    <#include "../common/header.ftl"/>
    <script type="text/javascript" src="/js/plugins/My97DatePicker/WdatePicker.js"></script>

    <script type="text/javascript">
        $(function(){
            $("#pagination").twbsPagination({
                totalPages:${pageInfo.pages}||1,
                visiblePages:5,
                startPage:${qo.currentPage},
                first:"首页",
                prev:"上一页",
                next:"下一页",
                last:"尾页",
                onPageClick:function(event,page){
                    $("#currentPage").val(page);
                    $("#searchForm").submit();
                }
            });

            $("#query").click(function(){
                $("#currentPage").val(1);
                $("#searchForm").submit();
            });

            //点击修改按钮
            $(".inputBtn").click(function () {
                // 4步走,清空,取值,回显,显示
                // 1. 清空
                $('#inputModal input').val('');
                $('#inputModal select').val('');
                // 2. 取值
                var obj = $(this).data('json');
                // 3. 编辑回显
                if (obj) {
                    $('#inputModal input[name="id"]').val(obj.id);
                    $('#inputModal input[name="name"]').val(obj.name);
                    $('#inputModal input[name="sequence"]').val(obj.sequence);
                    $('#inputModal select[name="state"]').val(obj.state+'');
                    $('#inputModal select[name="strategy.id"]').val(obj.strategyId);
                }
                // 4. 显示
                $('#inputModal').modal('show');
            });

            // 使用jQueryform修改模态框的提交方式-ajax方式,在表单提交之前
            $('#editForm').ajaxForm(function (data) {
                if (data.success) {
                    // 操作成功,刷新页面
                    location.reload();
                } else {
                    alert(data.msg);
                }
            });

            //保存提交
            $('#saveBtn').click(function () {
                $('#editForm').submit();
            });

        });

    </script>
</head>

<body>

<div class="container">
<#include "../common/top.ftl"/>
    <div class="row">
        <div class="col-sm-3">
        <#assign currentMenu = "strategyCatalog" />
				<#include "../common/menu.ftl" />
        </div>
        <div class="col-sm-9">
            <div class="page-header">
                <h3>攻略分类管理</h3>
            </div>
            <div class="row">
                <!-- 提交分页的表单 -->
                <form id="searchForm" class="form-inline" method="post" action="/strategyCatalog/list.do">
                    <input type="hidden" name="currentPage" id="currentPage" value="1"/>
                    <div class="form-group">
                    </div>
                    <div class="form-group">
                        <label>攻略搜索</label>
                        <input class="form-control" name="keyword" value="${(qo.keyword)!''}" placeholder="请输入分类关键字">
                    </div>
                    <div class="form-group">
                        <button id="query" type="button" class="btn btn-success"><i class="icon-search"></i> 查询</button>
                        <a href="javascript:" class="btn btn-success inputBtn">添加攻略分类</a>
                    </div>
                </form>
            </div>
            <div class="row">
                <table class="table">
                    <thead>
                    <tr>
                        <th>分类名称</th>
                        <th>所属攻略</th>
                        <th>排序</th>
                        <th>状态</th>
                        <th></th>
                    </tr>
                    </thead>
                    <tbody>
					<#list pageInfo.list as vo>
                        <tr>
                            <td>${vo.name}</td>
                            <td>${vo.strategy.title}</td>
                            <td>${vo.sequence!}</td>
                            <td>
                                <#if vo.state ==true>
                                    启用
                                <#elseif vo.state ==false>
                                    禁用
                                </#if>
                            </td>
                            <td>
                                <a href="javascript:" class="btn btn-sm btn-success inputBtn" data-json='${vo.json}'>
                                    <span class="glyphicon glyphicon-edit"></span> 修改
                                </a>
                            </td>
                        </tr>
					</#list>
                    </tbody>
                </table>

                <div style="text-align: center;">
                    <ul id="pagination" class="pagination"></ul>
                </div>
            </div>
        </div>
    </div>
</div>

<div id="inputModal" class="modal" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">编辑/增加</h4>
            </div>
            <div class="modal-body">
                <form id="editForm" class="form-horizontal" method="post" action="/strategyCatalog/saveOrUpdate.do">
                    <input type="hidden" name="id">
                    <div class="form-group">
                        <label class="col-sm-3 control-label">分类名称</label>
                        <div class="col-sm-7">
                            <input type="text" class="form-control" name="name" >
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">所属攻略</label>
                        <div class="col-sm-7">
                            <select name="strategy.id" class="form-control">
                                <#list strategies as s>
                                    <option value="${s.id}">${s.title}</option>
                                </#list>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">排序</label>
                        <div class="col-sm-7">
                            <input type="text" class="form-control" name="sequence" >
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">状态</label>
                        <div class="col-sm-7">
                            <select id="state" class="form-control" autocomplete="off" name="state" >
                                <option value="false">禁用</option>
                                <option value="true">启用</option>
                            </select>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <a href="javascript:void(0);" class="btn btn-success" id="saveBtn" aria-hidden="true">保存</a>
                <a href="javascript:void(0);" class="btn" data-dismiss="modal" aria-hidden="true">关闭</a>
            </div>
        </div>
    </div>
</div>

</body>
</html>